package com.wangfei.service;

import com.wangfei.entity.User;
import com.wangfei.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserService {

    @Autowired
    UserRepository userRepository;

    public User getUserById(Integer id) {
        return userRepository.findById(id).get();
    }

    public User saveUser(User user) {
//        userRepository.findBy()
        // 查询id>5的
        User user2 = new User();
        user2.setId(5);
        Example<User> example = Example.of(user2);
        Optional<User> user1 = userRepository.findOne(example);
        return userRepository.save(user);
    }
}
